<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回除法的浮点数余数</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.floor.html">« floor</a></li>
      <li style="float: right;"><a href="function.hexdec.html">hexdec »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.math.html">Math 函数</a></li>
    <li>返回除法的浮点数余数</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.fmod" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">fmod</h1>
   <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">fmod</span> &mdash; <span class="dc-title">返回除法的浮点数余数</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.fmod-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>fmod</strong></span>(<span class="methodparam"><span class="type">float</span> <code class="parameter">$num1</code></span>, <span class="methodparam"><span class="type">float</span> <code class="parameter">$num2</code></span>): <span class="type">float</span></div>

  <p class="para rdfs-comment">
   返回被除数（<code class="parameter">num1</code>）除以除数（<code class="parameter">num2</code>）所得的浮点数余数。余数（<var class="varname">r</var>）的定义是：num1
   = i * num2 + r，其中 <var class="varname">i</var> 是整数。如果 <code class="parameter">num2</code>
   是非零值，则 <var class="varname">r</var> 和
   <code class="parameter">num1</code> 的符号相同并且其数量值小于
   <code class="parameter">num2</code>。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.fmod-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">num1</code></dt>

     <dd>

      <p class="para">
       被除数
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">num2</code></dt>

     <dd>

      <p class="para">
       除数
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.fmod-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <code class="parameter">num1</code>/<code class="parameter">num2</code> 的浮点数余数。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.fmod-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3095">
    <p><strong>示例 #1 <span class="function"><strong>fmod()</strong></span> 的使用</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$x&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">5.7</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$y&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1.3</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$r&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fmod</span><span style="color: #007700">(</span><span style="color: #0000BB">$x</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$y</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;$r&nbsp;equals&nbsp;0.5,&nbsp;because&nbsp;4&nbsp;*&nbsp;1.3&nbsp;+&nbsp;0.5&nbsp;=&nbsp;5.7<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.fmod-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="language.operators.arithmetic.html" class="link"><code class="literal">/</code></a>——浮点除法</li>
    <li class="member"><a href="language.operators.arithmetic.html" class="link"><code class="literal">%</code></a>——整数取模</li>
    <li class="member"><span class="function"><a href="function.intdiv.html" class="function">intdiv()</a></span>——整数除法</li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>